import { ref } from 'vue'
import { getnetworkList } from '@/api/network'

/**
 * 网点列表服务
 */
export default function () {
  const getNetworkListLoading = ref(false)
  const total = ref(0)
  const networkList = ref<Array<NetworkAPIResponse.NetworkListItem>>([])
  const getNetworkListParam = ref<NetworkAPIRequest.GetNetworkListParam>({
    category: '',
    limit: 50,
    networkId: '',
    networkSearch: '',
    networkTypeId: '',
    page: 1,
    status: '',
    teamType: '',
    threeNetworkTypeId: '',
    twoNetworkTypeId: '',
    type: '',
  })

  const resetGetNetworkListParam = () => {
    getNetworkListParam.value = {
      category: '',
      limit: 50,
      networkId: '',
      networkSearch: '',
      networkTypeId: '',
      page: 1,
      status: '',
      teamType: '',
      threeNetworkTypeId: '',
      twoNetworkTypeId: '',
      type: '',
    }
  }

  const getNetworkList = async () => {
    try {
      getNetworkListLoading.value = true
      const res = await getnetworkList(getNetworkListParam.value)
      getNetworkListLoading.value = false
      networkList.value = res.data.data.rows
      total.value = Number(res.data.data.total)
    } catch (error) {
      getNetworkListLoading.value = false
    }
  }

  return {
    total,
    networkList,
    getNetworkListParam,
    getNetworkListLoading,
    getNetworkList,
    resetGetNetworkListParam,
  }
}
